package com.controller;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.init.resolvers.CurrentUser;
import com.init.resolvers.UserToken;
import com.service.AsyncService;

import test.lookup.AOrBFactory;
import test.lookup.AOrBService;

@Controller("test")
@RequestMapping("/test")
public class TestController {
	
	@Resource
	private AOrBFactory aOrBFactory;
	@Resource
	private AsyncService asyncService;
    
    @RequestMapping("/res")
    @ResponseBody
    public String filesUpload() {
    	AOrBService a = aOrBFactory.a();
    	a.say();
    	AOrBService b = aOrBFactory.b();
    	b.say();
    	AOrBService a2 = aOrBFactory.a();
    	a2.say();
		return "";
    	
    }
    
    @RequestMapping("/methodargumentresolver")
    @ResponseBody
    public Object filesUpload(@CurrentUser UserToken userToken,Model model, Map model2, ModelMap model3) {
    	model.addAttribute("a", "a");  
        model2.put("b", "b");
        model3.put("c", "c");  
        System.out.println(model == model2);  
        System.out.println(model2 == model3);
		return userToken;
    }
    
    @RequestMapping("/model")
    public ModelAndView model(Model model, Map model2, ModelMap model3) {
        model.addAttribute("a", "a");//①添加模型数据  
        ModelAndView mv = new ModelAndView("sucss");  
        mv.addObject("a", "update");//②在视图渲染之前更ce新③处同名模型数据  
        model.addAttribute("a", "new");//③修改①处同名模型数据  
        //视图页面的a将显示为"update" 而不是"new"
		return mv;
    }
    
    @ResponseBody
    @RequestMapping("/model")
    public Object testAsyn() {
        asyncService.asyncMethodWithReturnType(1);
        asyncService.asyncMethodWithVoidReturnType(1);
        asyncService.syncUnit(1);
		return null;
    }
    
}